<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
$(function(){
	//添加验证
	addValid();
	
	//保存按钮绑定事件
	$("#saveButton").click(function(){
		var docClassNames_array = document.getElementsByName("docClassNames");
		for ( var i = 0; i < docClassNames_array.length; i++) {
				if (null == docClassNames_array[i].value || '' == docClassNames_array[i].value) {
					alert("请点击选择数据！");
					docClassNames_array[i].focus();
					return false;
				}
		}
		
		if($("#docInfoForm").form('validate')){
			$(this).attr("disabled",true);
			$.messager.progress({ 
				title : '提示', 
				text : '文件正在上传中，请稍等....'  
				});
			$("#docInfoForm").ajaxSubmit({//此方法使用需要单独引用/js/extends/jquery.form.js
	            type: 'post', // 提交方式 get/post
	            url: "<c:url value='/docInfo/saveDocData' />", // 需要提交的 url
	            datatype: "json",
	            success: function(msg){
	            	 	var flag=false;
		            	try {
							flag=JSON.parse(msg).state=="200";
						} catch (e) {
							flag=JSON.stringify(msg).indexOf("200")!=-1;
						}
						$.messager.progress('close');
					    if(flag){
					    	 //去掉提示框，调用parent.closeDialog后弹窗马上关闭看不到效果
					    	 //$.messager.alert('提示','数据保存成功');
					    	 parent.closeDialog();
					    }else{
					    	 $.messager.alert('提示','数据保存失败');
					    	 $(this).attr("disabled",false);
					    }
				   }
	        });
			
			
		}
	});
	
});

/**
 * 打开树
 * 
 */
function openTree(index,num,docClassId){
	$("#docClassNames"+index).combotree ({
		url:"<c:url value='/docInfo/docClassTreeData?docClassId=' />"+docClassId + "&num="+num,
		onSelect:function(node){
			$("#docClassIds"+index).val(node.id);
		}
	 });
}

//添加验证
function addValid(){
	$("#title").textbox({
	    required: true
	});

	//文件
	$("#templateFile").filebox({  
	    required : true,  
	    width : '90%',  
	    multiple : true,  
	    //validType : ['fileSize[1024,"kb"]' ],  
	    buttonText : '浏览 ...',  
	    buttonAlign : 'right',
	    prompt : '请选择一个文件...',  
	    accept : 'application/msword' 
	});  
	
	$("#description").textbox({
		multiline:true,
		validType:'length[0,1000]'
	});
	
}